package com.fastbee.web.wnx;

import com.fastbee.common.annotation.Anonymous;
import com.fastbee.common.core.domain.AjaxResult;
import com.fastbee.common.utils.uuid.IdUtils;
import com.fastbee.web.wnx.entity.UpdateModule;
import com.fastbee.web.wnx.service.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.time.DateUtils;;
import org.quartz.Scheduler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.*;

/**
 * 设备参数监测Controller
 */
@Anonymous
@Api("测试方法")
@RestController
@RequestMapping("/test2")
@Component
public class WnxInterfacePlatformController {

    private static final Logger log = LoggerFactory.getLogger(DatabaseMetaService.class);
    @Autowired
    private DatabaseMetaService databaseMetaService;
    @Autowired
    private MonthlySalesStatisticsService monthlySalesStatisticsService;
    @Autowired
    private ProductionEquipmentService productionEquipmentService;
    @Autowired
    private ProductOrderTimeService productOrderTimeService;
    @Autowired
    private WarehouseLocationService warehouseLocationService;
    @Autowired
    private  ProductionRawService productionRawService;
    @Autowired
    private WarehouseTimeService warehouseTimeService;
    @Autowired
    private WarehouseMadeStockService warehouseMadeStockService;
    @Autowired
    private WarehouseConsumableMaterialService warehouseConsumableMaterialService;
    @Autowired
    private  ProductRealOrderService productRealOrderService;
    @Autowired
    private  ProductionBadService productionBadService;
    @Autowired
    private  ProductionUnqualifiedService productionUnqualifiedService;
    @Autowired
    private  WarehouseMadeInventoryService warehouseMadeInventoryService;
    @Autowired
    private  WarehouseRawInventoryService warehouseRawInventoryService;
    @Autowired
    private  ProductionInspectionService productionInspectionService;
    @Autowired
    private  ProductionTeamService productionTeamService;
    @Autowired
    private ProductionEquipmentSotpService productionEquipmentSotpService;
    @Autowired
    private WarehouseCurrentService warehouseCurrentService;
    @Autowired
    private  ProductionStatusService productionStatusService;
    @Autowired
    private  ProductionBadNumberService productionBadNumberService;
    @Autowired
    private ProductReturnReasonService productReturnReasonService;
    @Autowired
    private ProductReturnService productReturnService;
    @Autowired
    private ProductPassService productPassService;
    @Autowired
    private PurchaseMaterialService purchaseMaterialService;
    @Autowired
    private PurchaseReturnService purchaseReturnService;
    @Autowired
    private ProductionPlanService productionPlanService;
    @Autowired
    private PurchaseOrderService purchaseOrderService;
    @Autowired
    private ProductRankingService productRankingService;
    @Autowired
    private PurchaseMonthlySalesService purchaseMonthlySalesService;
    @Autowired
    private ProductAbnormalOrderService productAbnormalOrderService;
    @Autowired
    private ProductBeforeOrderService productBeforeOrderService;
    @Autowired
    private ProductOrderMonthService productOrderMonthService;
    @Autowired
    private ProductHalfOrderService productHalfOrderService;
    @Autowired
    private SupplierAssessmentService supplierAssessmentService;
    @Autowired
    private WarehouseUseService warehouseUseService;
    @Autowired
    private CustomerService customerService;

    @Autowired
    private Scheduler scheduler;


    @GetMapping("/test")
    @ApiOperation("测试接口平台接口")
    public AjaxResult test() {
        //月度销售额统计
        try{
            Date date = DateUtils.parseDate("2025-11-25","yyyy-MM-dd");
            monthlySalesStatisticsService.loadMonthlySalesStatistics(date);
            productionEquipmentService.loadProductionEquipment(date);
            productOrderTimeService.loadProductOrderTime(date);
            warehouseLocationService.loadWarehouseLocation(date);
            productionRawService.loadProductionRaw(date);
            warehouseTimeService.loadWarehouseTime(date);
            warehouseMadeStockService.loadWarehouseMadeStock(date);
            warehouseConsumableMaterialService.loadWarehouseConsumableMaterial(date);
            productRealOrderService.loadProductRealOrder(date);
            productionBadService.loadProductionBad(date);
            productionUnqualifiedService.loadProductionUnqualified(date);
            warehouseMadeInventoryService.loadWarehouseMadeInventory(date);
            warehouseRawInventoryService.loadWarehouseRawInventory(date);
            productionInspectionService.loadProductionInspection(date);
            productionTeamService.loadProductionTeam(date);
            productionEquipmentSotpService.loadProductionEquipmentSotp(date);
            warehouseCurrentService.loadWarehouseCurrent(date);
            productionStatusService.loadProductionStatus(date);
            productionBadNumberService.loadProductionBadNumber(date);
            productReturnReasonService.loadProductReturnReason(date);
            productReturnService.loadProductReturn(date);
            productPassService.loadProductPass(date);
            purchaseReturnService.loadPurchaseReturn(date);
            productionPlanService.loadProductionPlan(date);
            purchaseOrderService.loadPurchaseOrder(date);
            productRankingService.loadProductRanking(date);
            purchaseMonthlySalesService.loadPurchaseMonthlySales(date);
            productAbnormalOrderService.loadProductAbnormalOrder(date);
            productBeforeOrderService.loadProductBeforeOrder(DateUtils.addDays(date, -1));
            productOrderMonthService.loadProductOrderMonth(date);
            productHalfOrderService.loadProductHalfOrder(date);
            supplierAssessmentService.loadSupplierAssessment(date);
            warehouseUseService.loadWarehouseUse(date);
            customerService.loadCustomer();
        }catch (Exception e){
            log.warn("错误 失败: {}", e.getMessage());
        }
        return AjaxResult.success();
    }


    @GetMapping("/test2")
    @ApiOperation("测试接口平台接口")
    public void test2(){
        List<String> tableNames=new ArrayList<>(
                Arrays.asList(
                "szh_product_before_order","szh_product_order_abnormal",
                "szh_product_order_half","szh_product_order_month",
                "szh_product_order_time","szh_product_pass",
                "szh_product_ranking","szh_product_real_order",
                "szh_product_return","szh_product_return_reason",
                "szh_production_bad","szh_production_bad_number",
                "szh_production_equipment","szh_production_equipment_sotp",
                "szh_production_inspection","szh_production_plan",
                "szh_production_raw","szh_production_status",
                "szh_production_team","szh_production_unqualified",
                "szh_purchase_material","szh_purchase_monthly_amount",
                "szh_purchase_monthly_sales","szh_purchase_order",
                "szh_purchase_return","szh_supplier_assessment",
                "szh_warehouse_consumable","szh_warehouse_consumable_material",
                "szh_warehouse_current","szh_warehouse_location",
                "szh_warehouse_made_inventory","szh_warehouse_made_stock",
                "szh_warehouse_raw_inventory","szh_warehouse_raw_stock",
                "szh_warehouse_time","szh_warehouse_use"
                )
        );
        for(String tableName:tableNames){
            String selectSql=" SELECT id FROM  "+tableName ;
            String updateSql=" update "+tableName +" set ids=? where id=?" ;
            List<UpdateModule> dataList = databaseMetaService.queryForBeanList("secondary", selectSql, UpdateModule.class);
            for(UpdateModule updateModule:dataList){
                databaseMetaService.executeUpdate("secondary",updateSql, IdUtils.simpleUUID(),updateModule.getId());
            }
        }
    }
}

